home *** CD-ROM | disk | FTP | other *** search
- /*
- external_primitive.h
-
- definitions for writing external primitives for Marlais.
-
- by Patrick C. Beard.
-
- 68K version.
- */
-
- #ifndef __EXTERNAL_PRIMITIVE__
- #define __EXTERNAL_PRIMITIVE__
-
- #include <stddef.h>
- #include "object.h"
-
- // a set of procedures to support the use of external primitives.
-
- struct ExternalPrimitiveCallbacks {
- // access to primitive function loader.
- void (*init_prims) (int num, struct primitive prims[]);
-
- // Environment routines.
- Object (*eval) (Object obj); // evaluate an object.
- Object (*apply) (Object func, Object args); // apply a function to arguments.
- Object (*symbol_value) (Object sym); // look up a global symbol's value.
- void (*modify_value) (Object sym, Object new_val); // change a global symbol's value.
-
- // Error routines.
- Object (*error) (char* message, ...); // signals a runtime error. terminate args with NULL.
- Object (*warning) (char *msg, ...); // prints out a "warning: %s" message.
-
- // Object allocation primitives.
- Object (*make_foreign_ptr) (void* ptr); // make a <foreign-pointer>.
- Object (*make_byte_string) (char* str); // make a <string>.
- Object (*make_symbol) (char* symstr); // make a <symbol>.
- Object (*make_keyword) (char* keystr); // make a <keyword>.
- Object (*cons) (Object car, Object cdr); // make a <pair>.
- Object (*listem) (Object car, ...); // make a <list>. terminate args with NULL.
-
- // low-level access to the garbage collector.
- void* (*GC_malloc) (size_t size_in_bytes); // shouldn't be necessary.
- void* (*GC_malloc_atomic) (size_t size_in_bytes);
- void (*GC_free) (void* object_addr);
- void (*GC_add_roots) (void * low_address, void * high_address_plus_1);
- };
-
- typedef struct ExternalPrimitiveCallbacks ExternalPrimitiveCallbacks;
-
- struct ExternalPrimitiveObjects {
- Object unspecified_object, false_object, true_object; // common return values.
- };
-
- typedef struct ExternalPrimitiveObjects ExternalPrimitiveObjects;
-
- #define cExternalPrimitiveSupportVersion 0x0100
-
- struct ExternalPrimitiveSupport {
- short version; // version number of support structure.
- ExternalPrimitiveCallbacks* callbacks; // pointer to callbacks structure.
- ExternalPrimitiveObjects* objects; // pointer to objects structure.
- // other objects can be accessed by symbol_value callback.
- };
-
- typedef struct ExternalPrimitiveSupport ExternalPrimitiveSupport;
-
- typedef void (*ExternalPrimitiveLoader) (ExternalPrimitiveSupport* support);
-
- #endif /* __EXTERNAL_PRIMITIVE__ */
-